import {
  detail,
  getToEmail
} from '../../utils/api.common'

Page({

  data: {
    id: null,
    detailInfo: null,
    show: false,
    modelId: null,
    toUser: null,
  },

  submit(e) {
    this.setData({
      modelId: e.currentTarget.dataset.id,
      show: true
    })
  },
  toShare(e){

  },
  close() {
    this.setData({
      show: false,
      toUser: null
    })
  },

  // 确认
  confirm() {
    if (!this.data.toUser) {
      return wx.showToast({
        title: '请输入邮箱',
        icon: "none",
        mask: false,
        duration: 1500
      })
    }
    let params = {
      modelId: this.data.id,
      toUser: this.data.toUser,
    }
    getToEmail(params).then(res => {
      if (res.code === 200) {
        wx.showToast({
          title: '邮件发送成功',
          icon: "none",
          mask: false,
          duration: 1500
        })
        this.close()
      }
    })
  },

  // 绑定型号
  inputToUser(e) {
    this.setData({
      toUser: e.detail.value
    })
  },

  onLoad(options) {
    this.setData({
      id: options.id
    })
    let param = {
      id: options.id
    }
    detail(param).then(res => {
      if (res.code === 200) {
        this.setData({
          detailInfo: {
            id: res.data.id,
            modelName: res.data.modelName,
            modelYear: res.data.modelYear,
            modelBrand: res.data.modelBrand,
            thumbnail: res.data.thumbnail
          }
        })
      }
    })
  },


})